package com.pcs.controller;




import com.jfinal.core.Controller;
import com.pcs.common.EasyPage;
import com.pcs.model.Contact;

public class ContactController extends Controller {
	public void index() {
		
		EasyPage easyPage = new EasyPage();
		easyPage.setTotal(Contact.contactDao.paginate(getParaToInt("page"), 10).getTotalRow());
		easyPage.setRows(Contact.contactDao.paginate(getParaToInt("page"), 10).getList());
		renderJson(easyPage);
	}
	
	public void _index() {
		
		EasyPage easyPage = new EasyPage();
		easyPage.setTotal(Contact.contactDao._paginate(getParaToInt("page"), 10).getTotalRow());
		easyPage.setRows(Contact.contactDao._paginate(getParaToInt("page"), 10).getList());
		renderJson(easyPage);
	}
	
	
	
	public void save() {
		Contact contact = new Contact();
		contact.set("name", getPara("name"));
		contact.set("nickname", getPara("nickname"));
		contact.set("sex", getPara("sex"));
		contact.set("phone", getPara("phone"));
		contact.set("status", "A");
		contact.set("email", getPara("email"));
		contact.save();
		
		renderText("hello");
		//Contact.contactDao.setAttrs(contact);
		
	}
	
	public void edit() {
		setAttr("blog", Contact.contactDao.findById(getParaToInt()));
		
		renderText("hello");
	}
	
	
	public void update() {
		Contact contact = new Contact();
		contact.set("id", getPara("id"));
		contact.set("name", getPara("name"));
		contact.set("nickname", getPara("nickname"));
		contact.set("sex", getPara("sex"));
		contact.set("phone", getPara("phone"));
		contact.set("status", "A");
		contact.set("email", getPara("email"));
		
		contact.update();
		
		renderText("hello");
	}
	
	public void _update() {
		Contact contact = new Contact();
		contact.set("id", getPara("id"));
		contact = Contact.contactDao.findById(getPara("id"));
		contact.set("status", "A");
		
		contact.update();
		
		renderText("hello");
	}
	
	
	
	public void delete() {
		
		Contact contact = new Contact();
		contact.set("id", getPara("id"));
		contact.set("status", "I");
		contact.update();
		
		renderText("hello");
	}
	
	public void remove() {
		Contact.contactDao.deleteById(getPara("id"));
		
		renderText("hello");
	}
}
